<template>
  <div class="app-container customer-div">
    <el-menu :default-active="tab" class="el-menu-demo" mode="horizontal" @select="handleSelect">
      <el-menu-item index="my">我的</el-menu-item>
      <el-menu-item index="doing">复核处理中</el-menu-item>
      <el-menu-item index="done">复核已完成</el-menu-item>
      <el-menu-item index="department" v-if="departmentSaleDeliverDetails">部门</el-menu-item>
      <el-menu-item index="all" v-if="allSaleDeliverDetails">全部</el-menu-item>
    </el-menu>
    <div style="margin-top: 40px">
      <!--搜索-->
      <el-form :inline="true" :model="listQuery" size="mini" label-width="140px">
        <el-form-item label="订单号：">
          <el-input v-model="listQuery.orderSn" clearable></el-input>
        </el-form-item>
        <el-form-item label="发货单号：">
          <el-input v-model="listQuery.deliverSn" clearable></el-input>
        </el-form-item>
<!--        <el-form-item label="订单时间：">-->
<!--          <el-date-picker-->
<!--                  :default-time="['00:00:00', '23:59:59']"-->
<!--                  v-model="listQuery.createDate"-->
<!--                  type="daterange"-->
<!--                  format="yyyy 年 MM 月 dd 日"-->
<!--                  value-format="yyyy-MM-dd HH:mm:ss"-->
<!--                  range-separator="至"-->
<!--                  start-placeholder="开始日期"-->
<!--                  end-placeholder="结束日期">-->
<!--          </el-date-picker>-->
<!--        </el-form-item>-->
        <el-form-item label="发货日期：">
          <el-date-picker
                  :default-time="['00:00:00', '23:59:59']"
                  v-model="listQuery.deliverDate"
                  type="daterange"
                  format="yyyy 年 MM 月 dd 日"
                  value-format="yyyy-MM-dd HH:mm:ss"
                  range-separator="至"
                  start-placeholder="开始日期"
                  end-placeholder="结束日期">
          </el-date-picker>
        </el-form-item>
        <el-form-item label="客户编号：">
          <el-input v-model="listQuery.customerNumber"></el-input>
<!--          <el-autocomplete-->
<!--                  clearable-->
<!--                  class="inline-input"-->
<!--                  value-key="customerName"-->
<!--                  :fetch-suggestions="querySearch"-->
<!--                  v-model="listQuery.customerName"-->
<!--                  placeholder="请输入内容"-->
<!--                  @select="handleSelectCustomerName"-->
<!--                  :trigger-on-focus="false"-->
<!--          ></el-autocomplete>-->
        </el-form-item>
<!--        <el-form-item label="商品名称：" >-->
<!--          <el-input v-model="listQuery.goodsName"></el-input>-->
<!--        </el-form-item>-->
        <el-form-item label="送货类型：" >
          <el-select v-model="listQuery.isYunlianDeliver" filterable placeholder="请选择" clearable>
            <el-option label="运联发货" :value="1"></el-option>
            <el-option label="采购发货" :value="0"></el-option>
            <el-option label="自提" :value="2"></el-option>
          </el-select>
        </el-form-item>
<!--        <el-form-item label="订单号：">-->
<!--          <el-input v-model="listQuery.orderSn"></el-input>-->
<!--        </el-form-item>-->
        <el-form-item label="费用类型：" >
          <el-select v-model="listQuery.freightType" filterable placeholder="请选择" clearable>
            <el-option label="销售承担" value="sale"></el-option>
            <el-option label="采购承担" value="purchase"></el-option>
            <el-option label="运联承担" value="logistics"></el-option>
            <el-option key="customer" label="客户承担" value="customer"></el-option>
          </el-select>
        </el-form-item>
        <el-form-item label="是否修改过采购底价："  label-width="150px">
          <el-select v-model="listQuery.isChangeRealPrice" filterable placeholder="请选择" clearable>
            <el-option label="否" :value="0"></el-option>
            <el-option label="是" :value="1"></el-option>
          </el-select>
        </el-form-item>
        <el-form-item label="推荐类型：" >
          <el-select v-model="listQuery.introducerType" class="input-width" style="width:195px" placeholder="请选择" clearable >
            <el-option label="外部人员" :value="1"></el-option>
            <el-option label="内部人员" :value="2"></el-option>
          </el-select>
        </el-form-item>
        <el-form-item label="推荐人：" >
          <el-input v-model="listQuery.introducerName" clearable></el-input>
        </el-form-item>
        <el-form-item label="牌号：">
          <el-select v-model="listQuery.kingGoodsId" filterable placeholder="请选择" clearable>
            <el-option
              v-for="(item,index) in goodsList"
              :key="index"
              :label="item.goodsSn"
              :value="item.kingId">
            </el-option>
          </el-select>
        </el-form-item>
<!--        <el-form-item label="订单类型：" >-->
<!--          <el-select v-model="listQuery.isMoresuOnlineOrder" class="input-width" style="width:150px" placeholder="请选择" clearable>-->
<!--            <el-option label="销售订单" :value="0"></el-option>-->
<!--            <el-option label="推广订单" :value="1"></el-option>-->
<!--          </el-select>-->
<!--        </el-form-item>-->
        <el-form-item label="订单分类：" >
          <el-select v-model="listQuery.orderCustomerType" filterable clearable>
            <el-option
              v-for="(item,index) in orderCustomerTypeList"
              :key="index"
              :label="item.cddValue"
              :value="item.cddValue">
            </el-option>
          </el-select>
        </el-form-item>

        <el-form-item label="结算状态：" >
          <el-select v-model="listQuery.settleState" class="input-width" style="width:150px" placeholder="请选择" clearable>
            <el-option label="未结算" :value="0"></el-option>
            <el-option label="已结算" :value="1"></el-option>
          </el-select>
        </el-form-item>

        <el-form-item label="是否确认函：">
          <el-select v-model="listQuery.confirmationLetter" filterable placeholder="请选择" clearable style="width:100px">
            <el-option label="是" :value="1"></el-option>
            <el-option label="否" :value="0"></el-option>
          </el-select>
        </el-form-item>

        <el-form-item label="业务员：" v-if="listQuery.tab=='department'||listQuery.tab=='all'">
          <el-select v-model="listQuery.userId" filterable placeholder="请选择" clearable>
            <el-option
              v-for="(item,index) in userOptionList"
              :key="index"
              :label="item.userName"
              :value="item.userId">
            </el-option>
          </el-select>
        </el-form-item>

        <el-form-item label="是否长协：">
          <el-select v-model="listQuery.isAgreement"  placeholder="请选择" clearable>
            <el-option label="是" :value="1"></el-option>
            <el-option label="否" :value="0"></el-option>
          </el-select>
        </el-form-item>

        <el-form-item label="事业部：" v-if="listQuery.tab=='department'||listQuery.tab=='all'">
          <el-select v-model="listQuery.divsionDeptId" filterable placeholder="请选择" clearable>
            <el-option :value="item.divsionDeptId" :label="item.divsionDeptName" :key="item.divsionDeptId" v-for="item in divisionList"></el-option>
          </el-select>
        </el-form-item>
        <el-form-item label="是否负毛利：">
          <el-select v-model="listQuery.isNegativeProfit"  placeholder="请选择" clearable>
            <el-option label="是" :value="1"></el-option>
            <el-option label="否" :value="0"></el-option>
          </el-select>
        </el-form-item>

        <el-form-item label="有无杂费：">
          <el-select v-model="listQuery.isConsultation"  placeholder="请选择" clearable>
            <el-option label="有杂费" :value="2"></el-option>
            <el-option label="无杂费" :value="1"></el-option>
          </el-select>
        </el-form-item>
        <el-form-item label="是否后结算订单：">
          <el-select v-model="listQuery.isDelaySettleOrder" placeholder="请选择" clearable style="width:100px;">
            <el-option :key="1" label="是" :value="1"></el-option>
            <el-option :key="0" label="否" :value="0"></el-option>
          </el-select>
        </el-form-item>



        <el-form-item>
          <el-button
            @click="handleSearchList()"
            type="primary">
            查询
          </el-button>
          <el-button
            v-if="saleDeliverDetailsExport"
            @click="downloadExcel()"
            type="primary">
            导出
          </el-button>
        </el-form-item>
      </el-form>
    </div>

    <!--数据列表-->
    <div class="table-container">
      <div style="font-size:18px;line-height: 30px;padding:10px 0 ;color:red">
        销售总毛利：<span style="font-weight: bold">{{saleProfit}}</span>
        <span style="padding-left:20px;">发货总数量：</span><span style="font-weight: bold">{{sendAllNum}}</span>
<!--        <span style="padding-left:20px;">销售毛利：</span><span style="font-weight: bold">{{saleProfit}}</span>-->
      </div>
      <div style="font-weight: bold;line-height: 26px;font-size:14px">
          <div>销售毛利差异值 = 销售合同约定吨毛利-销售发货结算吨毛利</div>
          <div>为正，代表约定毛利＞发货毛利，销售员吨毛利  少了</div>
          <div>为负，代表约定毛利＜发货毛利，销售员吨毛利  多了</div>

      </div>
      <el-table
              v-loading="listLoading"
              :data="tableData"
              border
              style="width: 100%; margin-top: 20px">
        <el-table-column  label="订单号" width="150" align="center">
          <template slot-scope="scope">
            <el-link type="primary"  @click="toDetail('see',scope.row)" style="font-size:12px;vertical-align: middle">
              {{scope.row.orderSn}}
            </el-link>
            <img src="../../assets/images/xianshang.png" v-if="scope.row.isMoresuOnlineOrder == 1"  style="vertical-align: middle;"/>
          </template>
        </el-table-column>
        <el-table-column
                label="客户编号"
                width="300">
          <template slot-scope="scope">
              <div>
                {{scope.row.customerNumber}}
              </div>
              <!--是否有权限-->
              <div v-if="scope.row.isShowCustomerName">{{scope.row.customerName}}</div>
          </template>
        </el-table-column>

        <el-table-column
          label="订单分类"
          align="center"
          width="150">
          <template slot-scope="scope">
            {{scope.row.orderCustomerType}}
          </template>
        </el-table-column>

        <el-table-column
                label="牌号"
                align="center"
                width="150">
          <template slot-scope="scope">
            {{scope.row.goodsSn}}
          </template>
        </el-table-column>
        <el-table-column
                label="订单单价"
                width="100"
                align="center">
          <template slot-scope="scope">
            {{scope.row.goodsPrice}}
          </template>
        </el-table-column>
        <el-table-column  label="业务员" width="100" align="center">
          <template slot-scope="scope">
            {{scope.row.userRealName}}
          </template>
        </el-table-column>
        <el-table-column
                label="结算采购底价"
                width="120"
                align="center">
          <template slot-scope="scope">
              {{scope.row.purchaseActualPrice}}
          </template>
        </el-table-column>
        <el-table-column
                label="合同约定底价"
                width="120"
                align="center">
          <template slot-scope="scope">
            {{scope.row.purchasePrice}}
          </template>
        </el-table-column>
        <el-table-column
                label="本次发货数量"
                width="120"
                align="center">
          <template slot-scope="scope">
            {{scope.row.shipNum}}
          </template>
        </el-table-column>
        <el-table-column
          label="实际含税运费"
          width="120"
          align="center">
          <template slot-scope="scope">
            {{scope.row.actualTaxFreight}}
          </template>
        </el-table-column>
        <el-table-column
          label="费用类型"
          width="120"
          align="center">
          <template slot-scope="scope">
            {{scope.row.freightType}}
          </template>
        </el-table-column>
        <el-table-column
          label="单据类型"
          width="120"
          align="center">
          <template slot-scope="scope">
            <span v-if="parseFloat(scope.row.shipNum) < 0" style="color:red"> 退货单</span>
            <span v-else>发货单</span>
          </template>
        </el-table-column>
        <el-table-column
                label="销售发货现金价毛利"
                width="140"
                align="center">
          <template slot-scope="scope">
            <div v-if="scope.row.saleProfit < 0" style="width:100%;height:100%;background: red;color:#fff">
                 {{scope.row.saleProfit}}
            </div>
            <div v-else>
                 {{scope.row.saleProfit}}
            </div>
          </template>
        </el-table-column>

        <el-table-column
                label-class-name="bgth"
                label="吨/毛利"
                width="120"
                align="center">
          <template slot-scope="scope">
            {{scope.row.salePerProfit}}
          </template>
        </el-table-column>
        <el-table-column
                label-class-name="bgth"
                label="合同约定吨毛利"
                width="120"
                align="center">
          <template slot-scope="scope">
            {{scope.row.perAgreedProfit}}
          </template>
        </el-table-column>
        <el-table-column
                label-class-name="bgth"
                label="销售发货吨毛利"
                width="120"
                align="center">
          <template slot-scope="scope">
            {{scope.row.perSendProfit }}
          </template>
        </el-table-column>

        <el-table-column
                label="销售毛利差异值"
                width="120"
                align="center">
          <template slot-scope="scope">
            <div v-if="(scope.row.perAgreedProfit - scope.row.perSendProfit < -2) || (scope.row.perAgreedProfit - scope.row.perSendProfit > 2)" style="width:100%;height:100%;background: red;color:#fff">
              {{scope.row.perAgreedProfit | fifcount(scope.row.perSendProfit) }}
            </div>
            <div v-else>
              {{scope.row.perAgreedProfit |fifcount(scope.row.perSendProfit)}}
            </div>
          </template>
        </el-table-column>

        <el-table-column
                label="推荐佣金"
                width="120"
                align="center">
          <template slot-scope="scope">
            {{scope.row.saleCommissionProfit}}
          </template>
        </el-table-column>
        <el-table-column
          label="杂费（装卸费）"
          width="120"
          align="center">
          <template slot-scope="scope">
            {{scope.row.consultation}}
          </template>
        </el-table-column>
        <el-table-column
                label="销售实际发货毛利"
                width="120"
                align="center">
          <template slot-scope="scope">
              {{scope.row.saleActualProfit}}
          </template>
        </el-table-column>
        <el-table-column
                label="订单行备注"
                width="400">
          <template slot-scope="scope">
            {{scope.row.remark}}
          </template>
        </el-table-column>
        <el-table-column
          align="center"
          label="销售合同结算方式"
          width="150">
          <template slot-scope="scope">
            {{scope.row.salePayMethod}}
          </template>
        </el-table-column>

<!--            <el-table-column-->
<!--              align="center"-->
<!--              label="成本价结算方式"-->
<!--              width="150">-->
<!--              <template slot-scope="scope">-->
<!--                {{scope.row.goodsPayMethod}}-->
<!--              </template>-->
<!--            </el-table-column>-->
                <el-table-column
                        show-overflow-tooltip
                        label="收货确认函"
                        width="120"
                        align="center">
                  <template slot-scope="scope">
                      <div
                      v-for="(item,index) in scope.row.confirmationPic"
                      :key="index"
                      @click="fullImg2(item)"
                      style="color:#409EFF;cursor: pointer;word-break:break-all">查看附件</div>
                  </template>
                </el-table-column>
        <el-table-column
                fixed="right"
                label="结算状态"
                width="100"
                align="center">
          <template slot-scope="scope">
            {{scope.row.settleState | fifSettleState }}
          </template>
        </el-table-column>
        <el-table-column
                width="100"
                fixed="right"
                label="操作"
                align="center">
          <template slot-scope="scope">
              <el-button
                      v-if="scope.row.isNeedRecheck == 0"
                      type="text"
                      size="mini"
                      @click="seePop(scope.row)">申请复核
              </el-button>
            <el-button
                    v-if="scope.row.isNeedRecheck == 1"
                    type="text"
                    size="mini"
                    @click="toDetail('see',scope.row)">复核中
            </el-button>
            <el-button
                    v-if="scope.row.isNeedRecheck == 2"
                    type="text"
                    size="mini"
                    @click="toDetail('see',scope.row)">已复核
            </el-button>
          </template>
        </el-table-column>
      </el-table>
    </div>
    <div class="pagination-container">
      <el-pagination
              background
              @size-change="handleSizeChange"
              @current-change="handleCurrentChange"
              layout="total, sizes,prev, pager, next,jumper"
              :current-page.sync="listQuery.pageNum"
              :page-size="listQuery.pageSize"
              :page-sizes="[10,15,20]"
              :total="count">
      </el-pagination>
    </div>

    <!--回退弹窗-->
    <el-dialog
            :close-on-click-modal="false"
            title="审请复核"
            :visible.sync="dialogVisible"
            width="500px">
      <el-form :model="passForm" size="mini" label-width="100px" ref="passForm" :rules="rules">
        <el-form-item label="原因：" prop="remark">
          <el-input :autosize="{ minRows: 2, maxRows: 6}" type="textarea" v-model="passForm.remark"></el-input>
        </el-form-item>
      </el-form>
      <span slot="footer" class="dialog-footer">
              <el-button  @click="dialogVisible = false">取消</el-button>
              <el-button @click="shenhe" :loading="btnLoading" type="primary">确定</el-button>
          </span>
    </el-dialog>

    <!--放大图片-->
    <el-dialog
      :visible.sync="dialogVisible4"
      width="800px">
      <img :src="fullSrc" style="width:100%;"/>
    </el-dialog>


  </div>
</template>
<script>
import {
  getCustomerOption,
  getOrderUsersList,
  getDeliverDetailList,
  exportDeliverDetailList,
  orderGoodsList,
  applyRecheck,
  getConfigList
} from '@/api/partner';
import { formatDate } from '@/utils/date';
import store from '@/store';
import { mapGetters } from 'vuex';
import {divisionDeptList} from '@/api/company'
const defaultListQuery = {
  pageNum: 1,
  pageSize: 10,
  tab:'my',
  goodsName: '',
  createDate: null,
  deliverDate: null,
  customerName: null,
  deliverSn: '',
  type: 'sale',
  isYunlianDeliver: '',
  orderSn: '',
  freightType: '',
  isChangeRealPrice: '',
  introducerType: null,
  introducerName: null,
  goodsSn: '',
  kingGoodsId: '',
  isMoresuOnlineOrder: '',
  isNeedRecheck: 'my',
  settleState: '',
  confirmationLetter: '',
  userId:'',
  isAgreement:'',
  customerNumber:'',
  divsionDeptId:'',
  isNegativeProfit:'',
  isConsultation:'',
  orderCustomerType:'',
  isDelaySettleOrder:'',
};
export default {
  name: "index",
  data() {
    return {
      tab:'my',
      listQuery: JSON.parse(JSON.stringify(defaultListQuery)),
      roles:store.getters.roles?store.getters.roles:[],
      tableData: [],
      count: 0,
      listLoading: false,
      saleProfit: 0,
      sendAllNum: '',
      goodsList: [],
      dialogVisible: false,
      btnLoading: false,
      passForm: {
        remark: '',
      },
      rules: {
        remark: [{ required: true, trigger: 'blur', message: '请输入复核原因', }],
      },
      dialogVisible4: false,
      fullSrc: '',
      userOptionList: [],
      divisionList:[],
      orderCustomerTypeList:[]
    }
  },
  computed: {
    ...mapGetters([
      'name',
      'mobile',
      'userId'
    ]),
    departmentSaleDeliverDetails() {
      if (this.roles.indexOf("departmentSaleDeliverDetails") != -1) {
        return true
      } else {
        return false
      }
    },
    allSaleDeliverDetails() {
      if (this.roles.indexOf("allSaleDeliverDetails") != -1) {
        return true
      } else {
        return false
      }
    },
    saleDeliverDetailsExport() {
      if (this.roles.indexOf("saleDeliverDetailsExport") != -1) {
        return true
      } else {
        return false
      }
    },
  },
  created() {
    let now = new Date();
    let nowMonth = now.getMonth(); //当前月
    let nowYear = now.getFullYear(); //当前年
    //本月的开始时间
    let monthStartDate = new Date(nowYear, nowMonth, 1);
    //本月的结束时间
    let monthEndDate = new Date(nowYear, nowMonth + 1, 0, 23, 59, 59);
    let startDate = formatDate(monthStartDate, 'yyyy-MM-dd hh:mm:ss');
    let endDate = formatDate(monthEndDate, 'yyyy-MM-dd hh:mm:ss');
    this.listQuery.deliverDate = [startDate, endDate];

    if (localStorage.getItem('saleDeliverDetails')) {
      this.listQuery = JSON.parse(localStorage.getItem('saleDeliverDetails'));
      localStorage.removeItem('saleDeliverDetails');
    }

    if (this.$route.query.introducerName) {
      this.listQuery.introducerName = this.$route.query.introducerName;
    }
    this.getList();
    this.getUserOptionList();
    this.getOrderGoodsList();
    this.getDivisionDeptList()
    this.getOrderCustomerType()
  },
  filters: {
    formatCreateTime(time) {
      if (time) {
        let date = new Date(time);
        return formatDate(date, 'yyyy-MM-dd hh:mm:ss')
      } else {
        return '--'
      }
    },
    fifIntroducerType(val) {
      if (val == 1) {
        return '外部人员'
      } else if (val == 2) {
        return '内部人员'
      }
    },
    fifcount(val1, val2) {
      return (val1 - val2).toFixed(2)
    },

    fifSettleState(val) {
      if (val == 0) {
        return '未结算'
      } else if (val == 1) {
        return '已结算'
      }
    }

  },
  methods: {
    //获取订单分类列表
    getOrderCustomerType(){
      getConfigList({status:1}).then((res)=>{
        let orderCustomerType = res.find((el)=>{
          return  el.cdtCode == 'order_customer_type'
        })
        this.orderCustomerTypeList = orderCustomerType ? orderCustomerType.data : []
      })
    },
    //获取事业部列表
    getDivisionDeptList(){
      divisionDeptList().then((res)=>{
        this.divisionList = res
      })
    },
    //放大图片
    fullImg2(item) {
      window.open(item)
    },

    fullImg(src) {
      this.dialogVisible4 = true;
      this.fullSrc = src;
    },


    //查看发货单
    toDeliverCon(item) {
      let routeData = this.$router.resolve({ name: 'deliverCon', query: { id: item.deliverId, type: 'see' } });
      window.open(routeData.href);
    },
    //显示复核弹窗
    seePop(item) {
      this.dialogVisible = true;
      this.passForm.remark = '';
      this.passForm.dgId = item.dgId
    },
    //提交复核申请
    shenhe() {
      this.$refs.passForm.validate((valid) => {
        if (valid) {
          this.btnLoading = true;
          applyRecheck(this.passForm).then(() => {
            this.$message({
              message: '操作成功！',
              type: 'success'
            });
            this.btnLoading = false;
            this.dialogVisible = false;
            this.getList()
          }).catch(() => {
            this.btnLoading = false;
          })
        }
      });
    },



    getOrderGoodsList() {
      orderGoodsList().then((res) => {
        this.goodsList = res.list
      })
    },
    //去详情页
    toDetail(type, item) {
      let routeData = this.$router.resolve({ name: 'saleDetail', query: { id: item.orderId, type: type } });
      window.open(routeData.href);
      // this.$router.push({name:'saleDetail',query:{id:item.orderId,type:type}})
    },
    //下载excle
    downloadExcel() {
      let params = JSON.parse(JSON.stringify(this.listQuery));
      params.type = 'sale';
      exportDeliverDetailList(params).then((res) => {
        require.ensure([], () => {
          const { export_json_to_excel } = require('sheet/Export2Excel');
          const tHeader = res.title;
          const filterVal = res.columns;
          const list = res.list;
          const data = this.formatJson(filterVal, list);
          export_json_to_excel(tHeader, data, res.fileName);
        })
      })
    },

    //下载表格数据格式化
    formatJson(filterVal, jsonData) {
      return jsonData.map(v => filterVal.map(j => v[j]))
    },
    renderHeader(h) {
      return [h('div', {}, ['金蝶']), h('div', {}, ['成本单价'])]
    },

    renderHeader2(h) {
      return [h('div', {}, ['成本单价']), h('div', {}, ['现金价'])]
    },
    renderHeader3(h) {
      return [h('div', {}, ['采购底价']), h('div', {}, ['现金价'])]
    },
    //去客户详情页
    toCustomerDetail(item) {
      localStorage.setItem('saleDeliverDetails', JSON.stringify(this.listQuery));
      this.$router.push({ name: 'customerDetail', query: { id: item.customerId } })
    },

    //获取员工下拉选项
    getUserOptionList() {
      getOrderUsersList().then((res) => {
        this.userOptionList = res;
      })
    },

    //选择员工名称
    handleSelectUserName(key, item) {
      this.listQuery[key] = item.userId;
    },


    //客户名称输入匹配
    querySearch(queryString, cb) {
      getCustomerOption({ keywords: queryString }).then((res) => {
        cb(res);
      })
    },


    //选择客户名称
    handleSelectCustomerName(item) {
      this.listQuery.keywords = item.customerName
    },

    /**
     * 切换选择状态
     */
    handleSelect(key, keyPath) {
      if (key == 'my') {
        this.listQuery.isNeedRecheck = 'my';
        this.listQuery.tab = 'my';
      } else if (key == 'doing') {
        this.listQuery.isNeedRecheck = '1';
        this.listQuery.tab = 'my';
      } else if (key == 'done') {
        this.listQuery.isNeedRecheck = '2';
        this.listQuery.tab = 'my';
      } else {
        this.listQuery.isNeedRecheck = '';
        this.listQuery.tab = key;
      }
      this.listQuery.userId = '';
      this.handleSearchList();
    },
    handleSizeChange(val) {
      this.listQuery.pageNum = 1;
      this.listQuery.pageSize = val;
      this.getList();
    },
    handleCurrentChange(val) {
      this.listQuery.pageNum = val;
      this.getList();
    },

    handleSearchList() {
      this.listQuery.pageNum = 1;
      this.getList();
    },

    //获取发货明细列表
    getList() {
      this.listLoading = true;
      getDeliverDetailList(this.listQuery).then(response => {
        this.tableData = response.list;
        this.count = response.count;
        this.saleProfit = response.saleProfit;
        this.sendAllNum = response.sendAllNum;
        this.listLoading = false;
      }).catch(() => {
        this.listLoading = false;
      });
    },

    //判断是否可以申请复核
    fifClick(item) {
      //发货时间 零点的时间戳
      let shipTime = new Date(new Date(new Date(item.shipTime).getTime()).setHours(0, 0, 0, 0)).getTime();
      let now = new Date();
      let nowMonth = now.getMonth(); //当前月
      let nowYear = now.getFullYear(); //当前年
      //本月的开始时间
      let monthStartDate = new Date(nowYear, nowMonth, 1);
      let monthStartTime = monthStartDate.getTime();
      //本月的6号时间
      let monthSixDate = new Date(nowYear, nowMonth, 6);
      let monthSixTime = monthSixDate.getTime();
      //当前时间
      let nowTime = new Date().getTime();
      if (shipTime < monthStartTime) { // 发货时间不是当前月(上个月，或上上个月)
        if (nowTime > monthSixTime) { //当前时间大于当月6号，不能申请
          return false
        } else {
          return true
        }
      } else { //发货时间为当前月的，都能提交
        return true
      }
    },

  },
};
</script>

<style scoped lang="scss">
  .upload-div{
    text-align: center;
    position:relative;
    #upload{
      opacity: 0;
      position: absolute;
      z-index: 1;
      width:154px;
      height:40px
    }
  }
</style>
